/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = t_frstat_topology_add.c                            */
/*  NOTE      =                                                    */
/*  DATE      = 2015/02/02 by geyh                                 */
/*******************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <CUnit/Basic.h>
#include <CUnit/CUnit.h>

#include "frcomm.h"
#include "frmem.h"
#include "frsutl.h"
#include "frhash2.h"
#include "frstat_topology.h"
#include "apmtest_cunit.h"

static int __suite_init(void)
{
	return 0;
}

static int __suite_cleanup(void)
{
	return 0;
}

int frstat_topology_add(Frhash_header *p_st_hash_hdr
                                , u_int ui_sip, u_int ui_dip, u_short us_dport
                                , int i_l7_proto);

void frstat_topology_destroy(Frhash_header *p_st_list_header);
void frstat_topology_output(Frhash_header *p_st_list_header, void *socket_id);

static void case1(void)
{
    int i_ret = 0;
    Frhash_header *p_st_hash_hdr = NULL;
    u_int ui_sip = iptools_parse_ipaddr("192.168.1.1");
    u_int ui_dip = iptools_parse_ipaddr("192.168.0.1");
    u_short us_dport = 80;
    int i_l7_proto = 1433;

    i_ret = frstat_topology_add(p_st_hash_hdr, ui_sip, ui_dip, us_dport, i_l7_proto);

    CU_ASSERT_EQUAL(i_ret,FR_FAIL);

    return;
}

static void case2(void)
{
    int i_ret = 0;
    Frhash_header *p_st_hash_hdr = NULL;
    u_int ui_sip = iptools_parse_ipaddr("192.168.1.1");
    u_int ui_dip = iptools_parse_ipaddr("192.168.0.1");
    u_short us_dport = 80;
    int i_l7_proto = 1433;

    p_st_hash_hdr = frhash2_create2(50);

    i_ret = frstat_topology_add(p_st_hash_hdr, ui_sip, ui_dip, us_dport, i_l7_proto);

    CU_ASSERT_EQUAL(i_ret,FR_SUCC);
    frstat_topology_output(p_st_hash_hdr,NULL);
    frstat_topology_destroy(p_st_hash_hdr);

    frfree(p_st_hash_hdr);
    return;
}

static void case3(void)
{
    int i_ret = 0;
    Frhash_header *p_st_hash_hdr = NULL;
    u_int ui_sip = iptools_parse_ipaddr("192.168.1.1");
    u_int ui_dip = iptools_parse_ipaddr("192.168.0.1");
    u_short us_dport = 80;
    int i_l7_proto = 1433;

    p_st_hash_hdr = frhash2_create2(50);
    //构建测试链表
    i_ret = frstat_topology_add(p_st_hash_hdr, ui_sip, ui_dip, us_dport, i_l7_proto);

    i_ret = frstat_topology_add(p_st_hash_hdr, ui_sip, ui_dip, us_dport, i_l7_proto);

    CU_ASSERT_EQUAL(i_ret,FR_SUCC);
    frstat_topology_output(p_st_hash_hdr,NULL);
    frstat_topology_destroy(p_st_hash_hdr);

    frfree(p_st_hash_hdr);
    return;
}

static void case4(void)
{
    int i_ret = 0;
    Frhash_header *p_st_hash_hdr = NULL;
    u_int ui_sip = iptools_parse_ipaddr("192.168.1.1");
    u_int ui_dip = iptools_parse_ipaddr("192.168.0.1");
    u_short us_dport = 80;
    int i_l7_proto = 1433;

    p_st_hash_hdr = frhash2_create2(50);
    //构建测试链表
    i_ret = frstat_topology_add(p_st_hash_hdr, ui_sip, ui_dip, us_dport, i_l7_proto);

    ui_sip = iptools_parse_ipaddr("192.168.1.2");
    i_ret = frstat_topology_add(p_st_hash_hdr, ui_sip, ui_dip, us_dport, i_l7_proto);

    CU_ASSERT_EQUAL(i_ret,FR_SUCC);
    frstat_topology_output(p_st_hash_hdr,NULL);
    frstat_topology_destroy(p_st_hash_hdr);

    frfree(p_st_hash_hdr);
    return;
}
int add_suite()
{
	CU_pSuite pSuite = NULL;

	pSuite = CU_add_suite("t_frstat_topology_add 测试", __suite_init, __suite_cleanup);

	if (NULL == pSuite)
	{
		return 1;
	}


    //增加测试用例
   	CU_add_test(pSuite, "case1", case1);
   	CU_add_test(pSuite, "case2", case2);
   	CU_add_test(pSuite, "case3", case3);
   	CU_add_test(pSuite, "case4", case4);

    return 0;

}

int main(int argc, char **argv)
{
    fr_slab_init(52428800, "test");
    run_cunit(add_suite);
    fr_slab_destroy();

    return 0;
}